<template>
  <div class="example">
    <div class="op-btns">
      <div class="op-btns-title">
        <slot name="title" />
      </div>
      <!-- code button -->
      <LeeIcon
        class="icon-button"
        icon="icon-code"
        title="代码"
        @click="isShow = !isShow"
      />
    </div>

    <div class="example-showcase">
      <slot name="default" />
    </div>

    <!-- code view -->
    <el-collapse-transition>
      <div v-show="isShow">
        <div class="example-source">
          <div v-html="data" />
        </div>
      </div>
    </el-collapse-transition>
  </div>
</template>

<script lang="ts">
export default {
  name: 'Code',
};
</script>
<script lang="ts" setup>
import { ref } from 'vue';
defineProps({
  data: {
    //code data
    type: String,
    default: '',
  },
});
//是否显示code
const isShow = ref(false);
</script>

<style lang="scss" scoped>
.example {
  border-radius: 4px;
  .op-btns {
    padding: 8px;
    border-bottom: 1px solid #dcdfe6;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .op-btns-title {
      flex: 1;
      margin-right: 24px;
      font-weight: bold;
    }
    .icon-button {
      color: rgba(0, 0, 0, 0.4);
      &:hover {
        color: rgba(0, 0, 0, 0.6);
      }
    }
  }
  .describe {
    padding: 8px;
    border-bottom: 1px solid #dcdfe6;
  }
  .example-showcase {
    padding: 24px 0;
  }
  .example-source {
    padding: 16px;
    background: #f5f7fa;
  }
}
</style>
